#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>

void do_ls(int newfd)
{
	DIR* dir;//目录流
	struct dirent *item = NULL;
	char filename[1024];
	
	/*打开目录*/
	dir = opendir(".");
	if (NULL == dir) 
	{
		perror("opendir");
		exit(1);
	}

	/*读取目录*/
	while ((item = readdir(dir)) != NULL) 
	{
		bzero(filename, 1024);
		strncpy(filename, item->d_name, strlen(item->d_name));
		filename[strlen(filename)] = '\n';
		printf("********** %s", filename);
		write(newfd,filename,strlen(filename));//把文件名发给客户端
	}	

	/*关闭目录*/
	closedir(dir);

	/*挂电话*/
	close(newfd);
}

